import { userAccountLogin } from '@/api/user'
// 用户状态
export default {
  namespaced: true,
  // 箭头函数一条语句就可以不写return
  state: () => ({
    profile: {
      id: '',
      avatar: '',
      nickname: '',
      account: '',
      mobile: '',
      token: ''
    }
  }),
  mutations: {
    setInfo (state, payload) {
      state.profile = payload
    },
    deiInfo (state) {
      state.profile = {}
    }
  },
  actions: {
    async logOut ({ commit }) {
      commit('deiInfo')
      // { root: true } 第三个参数,站在上帝视角可以调用别的模块的方法
      commit('cart/setLoglist', [], { root: true })
    },
    async getInfo ({ commit }, formData) {
      const res = await userAccountLogin(formData)
      // console.log(res.result)
      commit('setInfo', res.result)
    }
  }
}
